Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

302
Vistas
"#define something something" in C

I'm looking at some microcontroller C headers and there is code like this:

#define OSCCONL OSCCONL
extern volatile uint8_t OSCCONL __attribute__((__sfr__));
#define OSCCONH OSCCONH
extern volatile uint8_t OSCCONH __attribute__((__sfr__));
#define CLKDIV CLKDIV
extern volatile uint16_t CLKDIV __attribute__((__sfr__));
__extension__ typedef struct tagCLKDIVBITS {...}

What is the purpose of those repetitive "#define A A" ?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

As the preprocessor does not know anything about the C language and variables you need to add some definitions know if the variable (variable) will be defined in the C code. You can use those definitions later in the code.

Example:

#if defined(OSCONL)
OSCONL = something;
#endif

And if your microcontroller does not have this register this part of the code will not be compiled. It is a very common technique.

EDIT:

But wouldn't that work the same if it just had #define OSCCONL

The idea is to have the same #define as variable or function name. It makes code consistent and easy to remember.

Otherwise, you would have to have different #define and object name making coding more difficult, as our would have to remember both. In this convention, you can read the documentation of the uC and use the same name to check if this object exists without remembering how the #define is called.

over 4 years ago · Santiago Trujillo Denunciar

0

One purpose could be that it can be used in a macro check such as #ifdef or #ifndef

This allows for conditional compiling where only parts of the source code will be compiled into the binary.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda